package com.itheima.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.itheima.constant.MessageConstant;
import com.itheima.entity.PageResult;
import com.itheima.entity.QueryPageBean;
import com.itheima.entity.Result;
import com.itheima.pojo.Address;
import com.itheima.pojo.Member;
import com.itheima.service.AddressService;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author 黑马程序员
 */
@RestController
@RequestMapping("/address")
public class AddressController {


    @Reference
    private AddressService addressService; // com.itheima.service.AddressService

    @GetMapping("/findAll")
    public Result findAll() {
        try {
            List<Address> items = addressService.findAll();
            return new Result(true, MessageConstant.GET1, items);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, MessageConstant.GET2);
        }
    }
    @GetMapping("/findById/{id}")
    public Result findById(@PathVariable Integer id){
        try{
            Address address = addressService.findById(id);
            return new Result(true,"成啦！",address);
        }catch (Exception e){
            e.printStackTrace();
            return new Result(false,"拉跨了");
        }
    }
}
